#ifndef WIDGETTREE_H
#define WIDGETTREE_H

#include <QObject>
#include <QLayout>
#include <QList>
#include <QSplitter>

/*
    继承了 QObject 类
    整体功能:
        实现了pagesWidget管理树，方便拖拽过程时操纵pagesWidget节点
*/

class WidgetTree : public QObject
{
    Q_OBJECT
public:
    explicit WidgetTree(QWidget* widget, int widgetType, QSplitter* splitter=nullptr, WidgetTree* parent=nullptr);

    QList<WidgetTree*> Children() const;
    WidgetTree* Parent() const;
    WidgetTree* Root() const;
    int WidgetType() const;
    int LayoutType() const;
    QWidget* Widget() const;
    QSplitter* Splitter() const;

    void addChild(QWidget* widget, int widgetType, QSplitter* splitter);
    void addChild(WidgetTree* child);
    void removeChild(WidgetTree* child);
    void Clear();
    WidgetTree* findChild(QWidget* widget);
    void PrintTree() const;

    void setParent(QObject* parent);

    enum {
        PAGE=0,
        SPLITTER
    };

private:
    WidgetTree* mParent {nullptr};
    QList<WidgetTree*> mChildren;

    QWidget* mWidget;
    QSplitter* mSplitter;
    int mWidgetType{-1};
    int mLayoutType{-1};

};

#endif // WIDGETTREE_H
